<extend name="Layout/ins_page" />
<block name="content">
	{:W('PageHeader/simple',array('name'=>'入库','search'=>'N'))}
	<form method='post' id="form_data" name="form_data" enctype="multipart/form-data"   class="well form-horizontal">
		<input type="hidden" id="type" name="type" value="1" />
		<div class="form-group col-sm-6">
			<label class="col-sm-4 control-label">入库产品：</label>
			<div class="col-sm-8">
				<select id="storehouse_product_id" name="storehouse_product_id" class="form-control store-house-class" onchange="show_number(this.options[this.options.selectedIndex].value)" check="require"  msg="请输入入库产品">
					<option value="">请选择</option>
					<foreach name="product" item="vo">
						<option value="{$vo.id}">{$vo.product}|{$vo.product_bh}</option>
					</foreach>
				</select>
			</div>
		</div>
		
		<div class="form-group col-sm-6 nownumber">
			<label class="col-sm-4 control-label">现有库存：</label>
			<div class="col-sm-8">
				<input class="form-control" id="now-number" type="text" name="now_number" disabled  value="0"/>
			</div>
		</div>
		
		<div class="form-group col-sm-6">
			<label class="col-sm-4 control-label">数量：</label>
			<div class="col-sm-8">
				<input class="form-control" id="number" type="text" name="number" check="require"  msg="请输入入库产品数量"/>
			</div>
		</div>

		<div class="form-group col-sm-6">
			<label class="col-sm-4 control-label" for="opreate_name">经办人：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" id="opreate_name" name="opreate_name" check="require" msg="请输入经办人" value="{$opreate_name}" readonly>
			</div>
		</div>
		
		<div class="form-group col-sm-6">
			<label class="col-sm-4 control-label" for="name">摘要：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" id="remark" name="remark"  />
			</div>
		</div>
		
		<div class="form-group col-sm-6">
			<label class="col-sm-4 control-label" for="name">图片：</label>
			<div class="col-sm-8">
				<input  type="file" id="product_img" name="product_img" />
			</div>
		</div>
		
		<div class="form-group">
			<div class="form-actions col-sm-10 col-sm-offset-2">
				<input class="btn btn-sm btn-primary" type="button" value="保存" onclick="save();" />
				<input class="btn btn-sm btn-default" type="button" value="取消" onclick="location.href='{:U('index')}'" />
			</div>
		</div>
		
	</form>
</block>

<block name="js">
	<script>
		function save() {
			sendForm("form_data", "{:U('addPost')}");
		}
		
		function show_number(id) {
			if(id.length<=0) {
				//ui_error('请选择库存产品');
				$('.nownumber').addClass('hide');
				return ;
			}
			var post_url = "{:U('showNum')}";
			$.ajax({
				type : "POST",
				dataType : "json",
				data : 'id='+id,
				url : post_url,
				success : function(data) {
					if (data.status) {
						$('.nownumber').removeClass('hide');
						$('#now-number').val(data.info.num);
					} else {
						ui_error(data.info);
					}
				}
			})
		}
	</script>
</block>